package com.itdr.utils;

import cn.hutool.core.bean.BeanUtil;
import com.itdr.pojo.*;
import com.itdr.pojo.vo.*;

import java.math.BigDecimal;
import java.util.List;

/**
 * ClassName: VOUtil
 * 日期: 2020/10/22 15:41
 *
 * @author Air张
 * @since JDK 1.8
 */
public class VOUtil {

    public static UserVO getUserVO(User u){
        UserVO uvo = new UserVO();
        BeanUtil.copyProperties(u,uvo);
        return uvo;
    }

    public static CategoryVO getCategoryVO(Category c){
        CategoryVO cvo = new CategoryVO();
        BeanUtil.copyProperties(c,cvo);
        return cvo;
    }

    public static ProductVO getProductVO(Product p){
        ProductVO pvo = new ProductVO();
        BeanUtil.copyProperties(p,pvo);
        return pvo;
    }

    public static ShippingVO getShippingVO(Shipping s){
        ShippingVO svo = new ShippingVO();
        BeanUtil.copyProperties(s,svo);
        return svo;
    }

    public static OrderItemVO getOrderItemVO(OrderItem s){
        OrderItemVO svo = new OrderItemVO();
        BeanUtil.copyProperties(s,svo);
        return svo;
    }

    public static OrderVO getOrderVO(Long orderId, BigDecimal payment, ShippingVO shippingVO, Integer status, List<OrderItemVO> voList){
        OrderVO svo = new OrderVO();
        svo.setOrderId(String.valueOf(orderId));
        svo.setPayment(payment);
        svo.setShippingVO(shippingVO);
        svo.setStatus(status);
        svo.setItemVOS(voList);
        return svo;
    }

    public static CartProductVO getCartProductVO(Cart c, Product p){
        CartProductVO cp = new CartProductVO();
        cp.setId(c.getId());
        cp.setUserId(c.getUserId());
        cp.setProductId(c.getProductId());
        cp.setQuantity(c.getQuantity());
        cp.setChecked(c.getChecked());
        cp.setMainImage(p.getMainImage());
        cp.setSubtitle(p.getSubtitle());
        cp.setPrice(p.getPrice());
        cp.setStock(p.getStock());
        return cp;
    }

    public static CartToTalVO getCartToTalVO(BigDecimal totalPrice, Integer num){
        CartToTalVO svo = new CartToTalVO();
        svo.setTotalPrice(totalPrice);
        svo.setNum(num);
        return svo;
    }
}
